package com.lc.zpyh.ui.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.zpyh.R;
import com.lc.zpyh.app.AppActivity;
import com.lc.zpyh.http.glide.GlideApp;
import com.lc.zpyh.http.request.UserCommentApi;
import com.lc.zpyh.http.response.UserCommentBean;
import com.lc.zpyh.other.IntentKey;
import com.lc.zpyh.util.SPUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/*
我的评价
 */
public class MyEvaluateActivity extends AppActivity {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseQuickAdapter<UserCommentBean.ListBean, BaseViewHolder> adapter;
    List<String> dataBeanList = new ArrayList<>();
    @Override
    protected int getLayoutId() {
        return R.layout.activity_myevaluate;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
               userComment();




    }

    private void userComment() {

        EasyHttp.post(this)
                .api(new UserCommentApi().setUserId(SPUtil.get(getContext(), IntentKey.USERID, "")).setPageNum("1").setPageSize("9999")).request(new HttpCallback<UserCommentBean>(this) {

            @Override
            public void onSucceed(UserCommentBean data) {
                if (data.getCode()==0) {
                    adapter = new BaseQuickAdapter<UserCommentBean.ListBean, BaseViewHolder>
                            (R.layout.item_myevaluate, data.getList()) {

                        @Override
                        protected void convert(BaseViewHolder viewHolder, UserCommentBean.ListBean commentOrderBean) {

                            viewHolder.setText(R.id.tv_shop_name, commentOrderBean.getCommodityName());

                            viewHolder.setText(R.id.tv_date, commentOrderBean.getCommentTime());
                            if (commentOrderBean.getNameOne() != null) {
                                viewHolder.setText(R.id.tv_yueshou, "规格:"+commentOrderBean.getNameOne());
                            }
                            if (commentOrderBean.getNameTwo() != null) {
                                viewHolder.setText(R.id.tv_yueshou, "规格:"+commentOrderBean.getNameOne() + "、" + commentOrderBean.getNameTwo());
                            }

                            GlideApp.with(getContext()).load(IntentKey.CAR_IMAGE+commentOrderBean.getImg()).into(((ImageView) viewHolder.getView(R.id.img_head)));
                            int starSpeed = commentOrderBean.getDeliverySpeed();
                            viewHolder.setImageResource(R.id.iv_speed_start_1, starSpeed >= 2 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_speed_start_2, starSpeed >= 4 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_speed_start_3, starSpeed >= 6 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_speed_start_4, starSpeed >= 8 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_speed_start_5, starSpeed >= 10 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);

                            int starhealth = commentOrderBean.getHealthSituation();
                            viewHolder.setImageResource(R.id.iv_hygiene_start_1, starhealth >= 2 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_hygiene_start_2, starhealth >= 4 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_hygiene_start_3, starhealth >= 6 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_hygiene_start_4, starhealth >= 8 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_hygiene_start_5, starhealth >= 10 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            int starpreservation = commentOrderBean.getHeatPreservation();
                            viewHolder.setImageResource(R.id.iv_effect_start_1, starpreservation >= 2 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_effect_start_2, starpreservation >= 4 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_effect_start_3, starpreservation >= 6 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_effect_start_4, starpreservation >= 8 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                            viewHolder.setImageResource(R.id.iv_effect_start_5, starpreservation >= 10 ? R.mipmap.ic_comment_full : R.mipmap.ic_comment_empty);
                        }
                    };

                    View emptyview = View.inflate(MyEvaluateActivity.this, R.layout.empty_emptylayout, null);

                    adapter.setEmptyView(emptyview);
                    recyclerView.setAdapter(adapter);

                }

            }
            @Override
            public void onFail(Exception e) {
                super.onFail(e);

            }
        });
    }
}
